count duplicate elements of array without sorting in java